package com.kingint.web.dueros.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.kingint.web.dueros.executor.commandExecutionService;
import com.kingint.web.dueros.model.*;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.MarkerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("v1/service")
public class CallBackController {

    @Autowired
    private commandExecutionService commandExecutionService;

//    @IgnoreAuth
    @PostMapping("/dueros")
    public CallBackResponse duerosCommand(@RequestBody CallBackRequestInit callBackRequestInit){
        log.debug("小度回调信息:"+callBackRequestInit);
        CallBackRequest callBackRequest = new CallBackRequest();
        BeanUtils.copyProperties(callBackRequestInit,callBackRequest);
//        Intents intents = JSON.parseObject(callBackRequestInit.getIntents(), Intents.class);
//        System.out.println(intents);
//        slots slots = JSON.parseObject(JSONObject.parseObject(callBackRequestInit.getIntents()).getJSONObject("slots").toString(), slots.class);
//        System.out.println(slots);
        callBackRequest.setIntents(JSON.parseObject(callBackRequestInit.getIntents(), Intents.class));
        callBackRequest.getIntents().setSlot(JSON.parseObject(JSONObject.parseObject(callBackRequestInit.getIntents()).getJSONObject("slots").toString(), slots.class));
        return CallBackResponse.ok(commandExecutionService.executeCommand(callBackRequest));
    }

}
